.PHONY: pull build down migrate-clickhouse migrate-clickhouse-reset integration generate-sql nuke-docker

pull:
	docker compose -f ./deployment/docker-compose.yaml pull

build: pull
	docker compose -f ./deployment/docker-compose.yaml build

down:
	docker compose -f ./deployment/docker-compose.yaml down

up: down build
	docker compose -f ./deployment/docker-compose.yaml up -d

integration: up
	@cd apps/api && \
	$(MAKE) seed && \
	pnpm test:integration

generate-sql:
	@rm -f ./go/pkg/db/schema.sql || true
	@touch ./go/pkg/db/schema.sql
	@echo "-- Code generated by Makefile. DO NOT EDIT." >> ./go/pkg/db/schema.sql
	@echo "--" >> ./go/pkg/db/schema.sql
	@echo "-- Source: internal/db/src/schema" >> ./go/pkg/db/schema.sql
	@rm -rf ./internal/db/out
	@cd internal/db && pnpm drizzle-kit generate --schema=src/schema/index.ts --dialect=mysql --out=out --name=init --breakpoints=false
	@echo "\n" >> ./internal/db/out/0000_init.sql
	@cat ./internal/db/out/0000_init.sql >> ./go/pkg/db/schema.sql

	@rm -rf ./internal/db/out


nuke-docker:
	docker stop $$(docker ps -aq)
	docker system prune -af
	docker volume prune --all -f
